/**=========================================================
 * Directive: datepicker-simple.js
 =========================================================*/

App.directive('datepicker', ['Utils',
    function(utils) {
        'use strict';
        
        return {
            restrict: 'EA',
            replace: true,
            template: function($element,$attrs){
                var optionModel = utils.isEmpty($attrs.optionModel) ? 'date' : $attrs.optionModel,
                    ngModel = utils.isEmpty($attrs.ngModel) ? 'datepickers.' + optionModel : $attrs.ngModel,
                    format = utils.isEmpty($attrs.format) ? 'yyyy-MM-dd' : $attrs.format,
                    style = utils.isEmpty($attrs.style) ? "width: 170px;": $attrs.style;
                    
                return '\
                    <p class="input-group" style="' + style + '">\
                        <input type="text" class="form-control" uib-datepicker-popup="' + format + '" ng-model="' + ngModel + '.date" \
                            is-open="' + ngModel + '.opened" datepicker-options="' + ngModel + '.dateOptions" ng-required="true" show-button-bar="false" />\
                        <span class="input-group-btn">\
                            <button type="button" style="height:35px" class="btn btn-default" ng-click="' + ngModel + '.opened=true">\
                                <i class="fa fa-calendar"></i>\
                            </button>\
                        </span>\
                    </p>\
                '
            }
        }
    }
]);
